package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppAssociations;
import com.ruoyi.app.domain.AppBanner;
import com.ruoyi.app.domain.AppUsers;
import com.ruoyi.app.service.IAppAssociationsService;
import com.ruoyi.app.service.IAppBannerService;
import com.ruoyi.app.service.IAppUsersService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api")
public class AppBaseController1 extends BaseController {

    @Autowired
    private IAppUsersService appUsersService;

    @Autowired
    private IAppAssociationsService appAssociationsService;

    @Autowired
    private IAppBannerService appBannerService;

    /**
     * 查询用户列表
     */

    @GetMapping("/users/list")
    public TableDataInfo listusers(AppUsers appUsers)
    {
        startPage();
        List<AppUsers> list = appUsersService.selectAppUsersList(appUsers);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @PostMapping("/users/export")
    public void exportusers(HttpServletResponse response, AppUsers appUsers)
    {
        List<AppUsers> list = appUsersService.selectAppUsersList(appUsers);
        ExcelUtil<AppUsers> util = new ExcelUtil<AppUsers>(AppUsers.class);
        util.exportExcel(response, list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @GetMapping(value = "/users/{userId}")
    public AjaxResult getInfousers(@PathVariable("userId") Long userId)
    {
        return success(appUsersService.selectAppUsersByUserId(userId));
    }

    /**
     * 新增用户
     */
    @PostMapping("/users/add")
    public AjaxResult addusers(@RequestBody AppUsers appUsers)
    {
        return toAjax(appUsersService.insertAppUsers(appUsers));
    }
    /**
     * 修改用户
     */
    @PutMapping("/users/edit")
    public AjaxResult editusers(@RequestBody AppUsers appUsers)
    {
        return toAjax(appUsersService.updateAppUsers(appUsers));
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/users/{userIds}")
    public AjaxResult removeusers(@PathVariable Long[] userIds)
    {
        return toAjax(appUsersService.deleteAppUsersByUserIds(userIds));
    }




//    /**
//     * 查询协会管理列表
//     */
//    @GetMapping("/associations/list")
//    public TableDataInfo listassociations(AppAssociations appAssociations)
//    {
//        startPage();
//        List<AppAssociations> list = appAssociationsService.selectAppAssociationsList(appAssociations);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出协会管理列表
//     */
//    @PostMapping("/associations/export")
//    public void exportassociations(HttpServletResponse response, AppAssociations appAssociations)
//    {
//        List<AppAssociations> list = appAssociationsService.selectAppAssociationsList(appAssociations);
//        ExcelUtil<AppAssociations> util = new ExcelUtil<AppAssociations>(AppAssociations.class);
//        util.exportExcel(response, list, "协会管理数据");
//    }
//
//    /**
//     * 获取协会管理详细信息
//     */
//    @GetMapping(value = "/associations/{id}")
//    public AjaxResult getInfoassociations(@PathVariable("id") Long id)
//    {
//        return success(appAssociationsService.selectAppAssociationsById(id));
//    }
//
//    /**
//     * 新增协会管理
//     */
//    @PostMapping("/associations/add")
//    public AjaxResult addassociations(@RequestBody AppAssociations appAssociations)
//    {
//        return toAjax(appAssociationsService.insertAppAssociations(appAssociations));
//    }
//
//    /**
//     * 修改协会管理
//     */
//    @PutMapping("/associations/edit")
//    public AjaxResult editassociations(@RequestBody AppAssociations appAssociations)
//    {
//        return toAjax(appAssociationsService.updateAppAssociations(appAssociations));
//    }
//
//    /**
//     * 删除协会管理
//     */
//    @DeleteMapping("/associations/{ids}")
//    public AjaxResult removeassociations(@PathVariable Long[] ids)
//    {
//        return toAjax(appAssociationsService.deleteAppAssociationsByIds(ids));
//    }



    /**
     * 查询轮播图
     列表
     */
    @GetMapping("/banner/list")
    public TableDataInfo list(AppBanner appBanner)
    {
        startPage();
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图
     列表
     */
    @PostMapping("/banner/export")
    public void export(HttpServletResponse response, AppBanner appBanner)
    {
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        ExcelUtil<AppBanner> util = new ExcelUtil<AppBanner>(AppBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图
     详细信息
     */
    @GetMapping(value = "/banner/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appBannerService.selectAppBannerById(id));
    }

    /**
     * 新增轮播图

     */
    @PostMapping("/banner/add")
    public AjaxResult add(@RequestBody AppBanner appBanner)
    {
        return toAjax(appBannerService.insertAppBanner(appBanner));
    }

    /**
     * 修改轮播图

     */
    @PutMapping("/banner/edit")
    public AjaxResult edit(@RequestBody AppBanner appBanner)
    {
        return toAjax(appBannerService.updateAppBanner(appBanner));
    }

    /**
     * 删除轮播图

     */
    @DeleteMapping("/banner/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appBannerService.deleteAppBannerByIds(ids));
    }
}
